package com.cskaoyan.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;

import java.util.concurrent.ThreadLocalRandom;

public class UserUtils {

    private static final String PREFIX = "wx";

    private static final int RANDOM_BOUND = 10000;

    private static final String DEFAULT_AVATAR_URL = "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80";

    public static Integer getUserId() {
        Subject subject = SecurityUtils.getSubject();
        //Integer userId = 1;
       Integer userId = (Integer) subject.getSession().getAttribute("userId");
        if (userId == null) {
            //throw new AuthorizationException();
            //throw new AuthenticationException();
        }
        return userId;
    }

    public static String getRandomNickname(String username){
        return PREFIX + "_" + username;
    }

    public static String getRandomCaptcha(){
        ThreadLocalRandom random = ThreadLocalRandom.current();
        return String.valueOf(random.nextInt(RANDOM_BOUND));
    }

    public static String getDefaultAvatarUrl(){
        return DEFAULT_AVATAR_URL;
    }

}
